package com.wuliang.generate.bean.entities.author;

import com.google.gson.annotations.Expose;
import com.wuliang.generate.common.core.basic.BasicEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.springframework.context.annotation.Lazy;

import javax.persistence.Cacheable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.util.Set;

/**
 * @author 邬魉
 */
@Data
@Lazy
@Entity
@Builder
@Cacheable
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("角色")
@EqualsAndHashCode(callSuper = true)
@Table(name = "t_author_permission", schema = "wuliang_generate_author")
public class AuthorPermission extends BasicEntity {

    @Expose
    @Column(name = "auth_permission_description", columnDefinition = "text null comment '角色描述'")
    @ApiModelProperty(name = "authPermissionDescription", value = "角色描述", dataType = "string")
    private String authPermissionDescription;

    @Expose
    @Column(name = "auth_permission_name", columnDefinition = "varchar(255) null comment '角色名称'")
    @ApiModelProperty(name = "authPermissionName", value = "角色名称", dataType = "string")
    private String authPermissionName;

    @Expose
    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "c_permission_role", joinColumns = {
            @JoinColumn(name = "permission_id", referencedColumnName = "id")
    }, inverseJoinColumns = {
            @JoinColumn(name = "role_id", referencedColumnName = "id")
    })
    private Set<AuthorRole> roles;
}
